package BVRServer;

import BVRNetworking.BVRN_Definitions;
import BVRNetworking.BVRN_Packet;

public class BVRS_PacketGenerator
{
	public static synchronized BVRN_Packet playerRotation(BVRS_Player player)
	{
		if (player == null)
			return new BVRN_Packet();
		
		BVRN_Packet packet = new BVRN_Packet(BVRN_Definitions.BVRN_PLAYER_ROTATION);
		
		packet.addParameter(player.getPlayerID());
		packet.addParameter(player.getRotation());
		
		return packet;
	}
	
	public static synchronized BVRN_Packet createLocalPlayer(BVRS_Player player)
	{
		if (player == null)
			return new BVRN_Packet();
		
		BVRN_Packet packet = new BVRN_Packet(BVRN_Definitions.BVRN_CREATELOCALPLAYER);
		
		packet.addParameter(player.getPlayerID());
		packet.addParameter(player.getPosition().x);
		packet.addParameter(player.getPosition().y);
		packet.addParameter(player.getRotation());
		packet.addParameter(player.getTeam().toString());
		
		return packet;
	}
	
	public static synchronized BVRN_Packet addPlayer(BVRS_Player player)
	{
		if (player == null)
			return new BVRN_Packet();
		
		BVRN_Packet packet = new BVRN_Packet(BVRN_Definitions.BVRN_CREATE_PLAYER);
		
		packet.addParameter(player.getPlayerID());
		packet.addParameter(player.getPosition().x);
		packet.addParameter(player.getPosition().y);
		packet.addParameter(player.getRotation());
		packet.addParameter(player.getTeam().toString());
		
		return packet;
	}
	
	public static synchronized BVRN_Packet setMovementSpeed(int speed)
	{
		BVRN_Packet packet = new BVRN_Packet(BVRN_Definitions.BVRN_SETMOVEMENTSPEED);
		
		packet.addParameter(speed);
		
		return packet;
	}
	
	public static synchronized BVRN_Packet playerPosition(BVRS_Player player)
	{
		BVRN_Packet packet = new BVRN_Packet();
		
		if (player == null)
			return packet;
		
		packet.setType(BVRN_Definitions.BVRN_SET_PLAYER_POSITION);
		packet.addParameter(player.getPlayerID());
		packet.addParameter(player.getPosition().x);
		packet.addParameter(player.getPosition().y);
		
		return packet;
	}
	
	public static synchronized BVRN_Packet playerVelocity(BVRS_Player player)
	{
		BVRN_Packet packet = new BVRN_Packet();
		
		if (player == null)
			return packet;
		
		packet.setType(BVRN_Definitions.BVRN_SET_PLAYER_VELOCITY);
		packet.addParameter(player.getPlayerID());
		packet.addParameter(player.getMovementSpeedX());
		packet.addParameter(player.getMovementSpeedY());
		
		return packet;
	}
}
